<include file=".:Common:header" />
<style type="text/css">
#LD a, #LD a:visited { color:#003264}
.list-div table th span { height:30px; line-height:30px; border-right:1px solid #BBDDE5; display:block; background:none; float:left; padding:0px 10px; overflow:hidden; cursor:pointer}
.list-div table tr { background:#FFFFFF;}
.list-div table th .cur { background:#F4FAFF; }
.ur_heres { height:35px; padding-left:20px; line-height:35px; overflow:hidden; font-size:14px; font-weight:bold; background:#F4FAFF}
</style>
<script type="text/javascript">
function add(){
	$('#add').window('open');
	$('#ff').show();
	$('#ff').form('clear');
	$('#ff').appendTo('#aa');
}
/*add*/
function close1(){
   $('#add').window('close');
  }
function insert(){
    $('#ff').form('submit',{
    url: '{:U('Purview/insert')}&ajax=true',
    onSubmit:function(){ 
	return $('#ff').form('validate');
	},
    success:function(data){
	var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				alertText('新增成功!','','{:U("purview/index")}');
				 close1();
		      	$('#datagrid').datagrid('reload');
				
			}
        }
   });
}
/*end add*/
/*edit*/
function close2(){
   $('#edit').window('close');
  }
  
  var id;
  function getSelect(id){
  ajaxPost('{:U("Purview/getInfoByid")}',{id:id},function(d){
  	res =runJson(d);
	if(res.status ==0){
		alertText(res.info,'error');
	}else{
	   var select = res.datas;
	   if(select){
		$('#edit').window('open');
		$('#ff').show();
		$('#ff').appendTo('#ee');
		 $('#ff').form('clear');
		 $('#ff').find('#mid').val(select.mid);
		 changTree(select.pid);
		$('#ff').find('#name').val(select.name);
		$('#ff').find('#tag').val(select.tag);
		$('#ff').find('#id').val(select.id);
	   }
   }
  })
  }
 
 function update(){
    $('#ff').form('submit',{
	url: '{:U('Purview/update')}&ajax=true',
    onSubmit:function(){ 
	return $('#ff').form('validate');
	},
    success:function(data){
	var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				alertText('修改成功!','','{:U("purview/index")}');
				 close2();
			}
        }
   });
}

function changTree(key){
	mid=$('#ff').find('#mid').val();
	ajaxPost('{:U("system/Node/getNodeByM")}',{'app_id':mid},function(d){
		d=runJson(d);
		if(d.status==0){
			alertText(d.info,'error');
		}else{
			var nodeid;
			var datas;
			var options =new Array();
			datas = d.data;
			nodeid=$("#ff").find('#pid');
			nodeid.empty();
			nodeid.append("<option value=''>请选择</option>");
			for(i=0;i<datas.length;i++){
						if(key && key==datas[i].id){
						options[i]="<option value='"+datas[i].id+"' selected>"+datas[i].name+"</option>";
						}else{
						options[i]="<option value='"+datas[i].id+"'>"+datas[i].name+"</option>";
						}
			}
			optionStr = options.join();
			nodeid.append(optionStr);
		}
	})

}
/*end edit*/
/*delete*/
function todelete(id){
				if (id){
					$.messager.confirm('提示', '确定删除吗？', function(r){
					if (r){
						ajaxPost("{:U('Purview/remove')}", {'id': id}, function(d){
						var d = runJson(d);
							if(d.status == 0){
								alertText(d.info, 'error');
							}else{
								alertText('删除成功!','','{:U("purview/index")}');
							}
						});
					}else return false;
					});	
				}
			}

</script>
<div class="wrapper clear">
	<div class="main">
        <if condition="!empty($button)">
            <div class="toolbar">
                <volist name="button" id="btn">
                <a href="{$btn.href}" id="add1" title="{$btn.text}">{$btn.text}</a>
                </volist>
            </div>
            </if>
		<div class="search">
            <div class="searchbox">
            
<div class="easyui-tabs">
  <foreach name="tree" item="list">
    <div title="{$list.name}" style="padding:10px;"> 
      <!--start-->
      <div class="easyui-tabs">
        <foreach name="list['child']" item="child">
          <div title="{$child.name}" style="padding:10px;"> 
            <!--start-->
            <foreach name="child['node']" item="node">
            <div class="list-div_1">
              <table width="100%" class="listdiv" id="LD" style="border-bottom:none; border-right:none;">
                <tr>
                  <td style="padding-left:20px; padding-top:5px; padding-bottom:5px;text-align:left;border-bottom:none"><b style="font-size:13px;color:#005EBB">{$node.name}</b>[{$node.node_name}]&nbsp;&nbsp; </td>
                  <td width="70%" style="padding-left:20px; padding-top:5px; padding-bottom:5px;text-align:left;border-bottom:none;"><php>foreach($node['tag'] as $tag){</php>
                    <b style="color:#005EBB">{$tag.name}</b>[{$tag.tag}]&nbsp;&nbsp;
                    <notempty name="view['edit']"> <a href="#" onclick="getSelect('{$tag.id}')">
                      <php>echo L('UPDATE');</php>
                      </a> </notempty>
                    <notempty name="view['delete']"> <a href="#" onclick="todelete('{$tag.id}')">
                      <php>echo L('DELETE');</php>
                      </a> </notempty>
                    <br />
                    <php>}</php></td>
                </tr>
              </table>
            </div>  
            </foreach>
            <!--end--> 
          </div>
        </foreach>
      </div>
      <!--end--> 
    </div>
  </foreach>
</div>

<!--公用-->
<form id="ff" method="post" style="display:none">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
    <tr>
      <td class="label">应用：</td>
      <td><select name="mid" id="mid" onchange="changTree()">
          <option value="0">请选择</option>
          
			{$opiontree}
            
        </select></td>
    </tr>
    <tr>
      <td class="label">节点：</td>
      <td><select name="pid" id="pid">
          <option value="0">请选择</option>
        </select></td>
    </tr>
    <tr>
      <td class="label">模块名：</td>
      <td><input type="text" class="input" name="name" id="name" style="width:100px;" /></td>
    </tr>
    <tr>
      <td class="label">标识：</td>
      <td><input type="text" class="input" name="tag" id="tag" style="width:100px;" /></td>
    </tr>
    <input type="hidden" name="id" id="id"/>
  </table>
</form>
<!--end--> 
<!--添加-->
<div id="add" class="easyui-window" title="添加" style="width:500px;height:280px;"  iconCls="icon-add" closed="true" maximizable="false" minimizable="false" collapsible="false" resizable="false" modal="true" shadow="true">
  <div id="aa"></div>
  <div class="tobutton"><a class="easyui-linkbutton" iconCls="icon-add2" href="javascript:void(0)" onclick="insert()">新增</a> <a class="easyui-linkbutton" iconCls="icon-cancel2" href="javascript:void(0)" onclick="close1()">取消</a> </div>
</div>
<!--end添加--> 
<!--edit-->
<div id="edit" class="easyui-window" title="修改" style="width:500px;height:280px;" iconCls="icon-edit" closed="true" maximizable="false" minimizable="false" collapsible="false" resizable="false" modal="true" shadow="true">
  <div id="ee" > </div>
  <div class="tobutton"> <a class="easyui-linkbutton" iconCls="icon-ok2" href="javascript:void(0)" onclick="update()">修改</a> <a class="easyui-linkbutton" iconCls="icon-cancel2" href="javascript:void(0)" onclick="close2()">取消</a> </div>
</div>
<!--end_edit-->            
            
            
			</div>
		</div>		
	</div>
</div>	            
<include file=".:Common:footer" />